﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using RFMobile.Database;
using RFMobile.Machines;

namespace RFMobile
{
    public partial class detailOperationScreen : Form
    {
        DatabaseManager operationSet;
        DataRow drOperation;
        DataRow drUser;
        Int32 id_operation;
        Int32 id_user;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="arr">Array de ID's</param>
        public detailOperationScreen(Int32 _comtec_id_operation)
        {
            id_operation = _comtec_id_operation;
            operationSet = new DatabaseManager();
            operationSet.BuildDataSet(new String[] { "operation", "users" }, "operationSet");
            drOperation = operationSet.Ds.Tables["operation"].Rows.Find(id_operation);
            drUser = operationSet.Ds.Tables["users"].Rows.Find(drOperation["comtec_id_user"]);

            InitializeComponent();

            this.ShowDialog();
        }

        private String operationType(object i)
        {
            if (i.ToString().Equals("1"))
                return ("Mantencion");
            if (i.ToString().Equals("2"))
                return ("Emergencia");
            if (i.ToString().Equals("3"))
                return ("Instalacion");
            return ("");
        }

        private void menuItem3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void menuItem2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void detailOperationScreen_Load(object sender, EventArgs e)
        {
            statusBar1.Text = "N° Operacion :" + drOperation["comtec_id_operation"].ToString();
            codTextBox.Text = drOperation["comtec_id_operation"].ToString();
            typeOperationTextBox.Text = operationType(drOperation["operation_type"]);
            responsibleTextBox.Text = drUser["name"].ToString() + " " + drUser["lastname1"].ToString() + " " + drUser["lastname2"].ToString();
            diagnosisTextBox.Text = drOperation["diagnosis"].ToString();
            changedPartsTextBox.Text = drOperation["changed_parts"].ToString();
            notesTextBox.Text = drOperation["notes"].ToString();

            String[] dateIni;
            String[] dateFin;

            dateIni = drOperation["operation_date_start"].ToString().Split(new Char[] { ' ' });
            dateFin = drOperation["operation_date_end"].ToString().Split(new Char[] { ' ' });

            fecha_ini_TextBox.Text = dateIni[0];
            fecha_fin_TextBox.Text = dateFin[0];

            hora_ini_TextBox.Text = dateIni[1];
            hora_fin_TextBox.Text = dateFin[1];

            dateIni = null;
            dateFin = null;
        }
    }
}